//
//  SearchTextField.swift
//  ZZUI
//
//  Created by 张文晏 on 2018/12/27.
//  Copyright © 2018 张文晏. All rights reserved.
//

import UIKit

public class SearchTextField: UITextField {
    
    lazy var imageView: UIImageView = {
        let imv = UIImageView(frame: CGRect(x: 10, y: (bounds.height - 16) / 2, width: 16, height: 16))
        imv.contentMode = .scaleAspectFit
        return imv
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI() {
        self.backgroundColor = UIColor(hex: 0xeff1f2)
        self.returnKeyType = .search
        self.clearButtonMode = .whileEditing
        let leftView = UIView(frame: CGRect(x: 0, y: 0, width: 36, height: bounds.height))
        leftView.addSubview(imageView)
        imageView.image = NCUIBundle.image("ui_search_text_field_search")
        self.leftView = leftView
        self.leftViewMode = .always
        self.textColor = .black
    }
    
    public func setIcon(_ image: UIImage?) {
        imageView.image = image
    }
}
